package com.sogou.ime.ui.settings.dynamic;

import android.graphics.Canvas;
import android.view.SurfaceHolder;

public class UIViewDrawThread extends Thread{
	//private int sleepSpan = 1;
	private boolean flag = true;
	UIView myUIView;//
	SurfaceHolder surfaceHolder = null;
	
	public UIViewDrawThread(UIView myUIView,SurfaceHolder surfaceHolder){
		this.myUIView = myUIView;
		this.surfaceHolder = surfaceHolder;
	}
	public void run(){
		Canvas c;
		while(flag){
			c = null;
			try {
				synchronized (this.surfaceHolder) {
					// Lock the Canvas
				    c = surfaceHolder.lockCanvas(null);
				    myUIView.onDraw(c);
				    //Thread.sleep(sleepSpan);//sleep
			    }
			} catch (Exception e) {
				e.printStackTrace();
			} finally {
			    if (c != null) {
			    	//update the canvas
			        surfaceHolder.unlockCanvasAndPost(c);
			    }
			}
		}
	}
    public void setFlag(boolean flag) {//set the loop flag
    	this.flag = flag;
    }	
}
